package com.jh.user.service;

import com.jh.user.util.CommonsUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jh.user.business.BankCodeBusiness;

@Controller
@EnableAutoConfiguration
public class BankCodeService {

	private static final Logger LOG = LoggerFactory.getLogger(BankCodeService.class);

	@Autowired
	public BankCodeBusiness bankCodeBusiness;

	//根据银行名称获得银行编码
	@RequestMapping(method=RequestMethod.POST,value=("/v1.0/user/bankcode/getcodebyname"))
	public @ResponseBody Object getcodebyname(@RequestParam(value="name") String name) {
		try {
			String codeByName = bankCodeBusiness.getCodeByName(name);

			if(StringUtils.isNotBlank(codeByName)){
				return CommonsUtil.returnSuccess(codeByName);
			}else{
				return CommonsUtil.returnError("没有该银行卡！");
			}
		}catch (Exception e){
			LOG.error("BankCodeService.getcodebyname, 查询银行卡异常" + e);
			return CommonsUtil.returnError("查询银行卡失败！");
		}
	}


}
